package com.buydeem.builder;

/**
 * Lombok @Builer 实现原理
 *
 * @author zengchao
 * @date 2022-04-25 17:08:08
 */
public class User {
    private String name;
    private Integer age;
    private String sex;

    public User(Builder builder) {
        this.name = builder.name;
        this.age = builder.age;
        this.sex = builder.sex;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }

    private static class Builder{
        private String name;
        private Integer age;
        private String sex;

        public Builder() {
        }

        public Builder name(String name){
            this.name = name;
            return this;
        }

        public Builder age(Integer age){
            this.age = age;
            return this;
        }

        public Builder sex(String sex){
            this.sex = sex;
            return this;
        }

        public User build(){
            return new User(this);
        }
    }

    public static void main(String[] args) {
        User mac = new User.Builder().name("mac").age(18).sex("man").build();
        System.out.println(mac);
    }
}
